Google News
logo
XML - Interview Questions
What does “xmlns” in XML mean?
Basically, every element (or attribute) in XML belongs to a namespace, a way of "qualifying" the name of the element.
 
Imagine you and I both invent our own XML. You invent XML to describe people, I invent mine to describe cities. Both of us include an element called name. Yours refers to the person’s name, and mine to the city name—OK, it’s a little bit contrived.
<person>
    <name>Ramana</name>
    <age>31</age>
    <homecity>
        <name>India</name>
        <lat>123.024</lat>
        <long>120.010</long>
    </homecity>
</person>
If our two XMLs were combined into a single document, how would we tell the two names apart? As you can see above, there are two name elements, but they both have different meanings.
 
The answer is that you and I would both assign a namespace to our XML, which we would make unique:
<personxml:person xmlns:personxml="https://www.freetimelearning.com/xml/person"
                  xmlns:cityxml="http://www.freetimelearn.com/xml/cities">
    <personxml:name>Ramana</personxml:name>
    <personxml:age>31</personxml:age>
    <cityxml:homecity>
        <cityxml:name>India</cityxml:name>
        <cityxml:lat>123.024</cityxml:lat>
        <cityxml:long>120.010</cityxml:long>
    </cityxml:homecity>
</personxml:person>
Now we’ve fully qualified our XML, there is no ambiguity as to what each name element means. All of the tags that start with personxml: are tags belonging to your XML, all the ones that start with cityxml: are mine.
Advertisement